<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>

<div style="margin:20px 0;"></div>
<div class="easyui-panel">
	<div style="padding:10px 60px 20px 60px">
<%--     	<form id="userForm" method="post" action="<c:url value='/userinf/saveUserInf.do'/>"> --%>
		<form id="userForm" method="post">
	    	<!-- 用户代码 -->
	    	<input type="hidden" id="user_uuid" name="user_uuid" value="${entity.user_uuid}"/>
	    	<input type="hidden" id="loginName" value="${entity.login_name}"/>
	    	<input type="hidden" id="phone" value="${entity.mobile}"/>
	    	<!-- 机构代码 -->
	    	<input type="hidden" id="ins_uuid" name="ins_uuid" value="${entity.ins_uuid}"/>
	    	<table cellpadding="5" style="width:100%;width:100%">
	    		<tr>
	    			<td>登录账号:</td>
	    			<td><input class="easyui-textbox" type="text" id="login_name" name="login_name" data-options="required:true" value="${entity.login_name}"/></td>
	    			<td>用户类别:</td>
	    			<td><code:codeSelect name="user_category" id="user_category" code_type="USER_CATEGORY" selectId="${entity.user_category}"></code:codeSelect></td>
	    		</tr>
	    		<tr>
	    			<td>真实姓名:</td>
	    			<td><input class="easyui-textbox" type="text" name="user_name" data-options="required:true" value="${entity.user_name}"/></td>
	    			<td>身份证号:</td>
	    			<td><input class="easyui-textbox" type="text" name="card_number" data-options="validType:'idcard'" value="${entity.card_number}"/></td>
	    		</tr>
	    		<tr>
	    			<td>电话:</td>
	    			<td><input class="easyui-textbox" type="text" id="mobile" name="mobile" data-options="validType:'mobile'" value="${entity.mobile}"/></td>
	    			<td>电子邮件:</td>
	    			<td><input class="easyui-textbox" type="text" name="email" data-options="validType:'email'" value="${entity.email}"/></td>
	    		</tr>
	    		<tr>
	    			<td>所属机构:</td>
	    			<td>
	    				<input class="easyui-textbox" type="text" data-options="required:true" readonly="readonly" id="inst_name" value="${entity.inst_name}"/>
    					<a href="javascript:void(0)" class="easyui-linkbutton detail-remove" iconCls="icon-search" id="selectBtn">选择</a>
    				</td>
    				<td>账号别名:</td>
	    			<td><input class="easyui-textbox" type="text" name="alias_name" value="${entity.alias_name}"/></td>
	    		</tr>
	    		<tr>
	    			<td>备注:</td>
	    			<td><input class="easyui-textbox" name="descpt" data-options="multiline:true" value="${entity.descpt}"/></td>
	    		</tr>
	    	</table>
	    	<div style="text-align:center;padding:5px">
		    	<jiepos:buttonDetailTag menuCode="${menuCode}" formId="userForm"></jiepos:buttonDetailTag>
		    </div>
    	</form>
    </div>
</div>
<script type="text/javascript">
	$(function(){
		init();
		/*选择按钮*/
		$("#selectBtn").click(function(){
			showInsTree(selected, $("#ins_uuid").val());
		});
	});
	/*确定按钮回调*/
	function selected(nodes){
		if(nodes && nodes.length > 0){
			$("#inst_name").textbox("setValue", nodes[0].NAME);
			$("#ins_uuid").val(nodes[0].ID);
		}
	}
		
	/*登录名验重*/
	function checkLoginName(){
		if(!$("#userForm").form("validate")){
			return false;
		};
		var loginName = $("#loginName").val(),phone = $("#phone").val(),isExist = true;
		if((!loginName && !phone) || (phone != $("#mobile").val())){
			$.jpajax({
				url: "checkLoginName.do",
				data: {loginName: $("#login_name").val(), phone: $("#mobile").val(), uuid:$("#user_uuid").val()},
				success: function(result){
					if(result == 1){
						isExist = !isExist;
						$.jpmessage.warning("电话已经存在");
					}else if(result == 2){
						isExist = !isExist;
						$.jpmessage.warning("用户登录名已经存在");
					}
				}
			});
		}
		return isExist;
	}
	
	function saveUser(urls){
		/*表单提交*/
		$("#userForm").form('submit',{
			url: urls,
			onSubmit: checkLoginName,
			success: function(data){
				if(data === "true"){
					window.history.back(-1);
				}else{
					$.jpmessage.error("用户信息保存失败");
				}
			}
		});
	}
	
	function init(){
		if($("#user_uuid").val()){
			$("#login_name").combo("readonly", true);
		}
	}
</script>